<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<link rel="stylesheet" href="/leaflet/leaflet.css" />
<link rel="stylesheet" href="../leaflet-search.css" />
<link rel="stylesheet" href="../style.css" />
</head>

<body>
<h3><a href="../">Leaflet.Control.Search</a></h3>

<h4>JSONP Example: <em>search locations by third party jsonp service, with filter data</em></h4>
<div id="map"></div>

<div id="post-it">
<b>Search values:</b><br />
OpenStreetMap Data offer by MapQuest Open Platform<br />
<small><a href="http://open.mapquestapi.com/nominatim/">open.mapquestapi.com</a></small>
</div>

<script src="/leaflet/leaflet.js"></script>
<script src="../leaflet-search.js"></script>
<script>

	var map = new L.Map('map', {zoom: 9, center: new L.latLng([41.575730,13.002411]) });
	map.addLayer(new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'));	//base layer
	
	var jsonpurl = 'http://open.mapquestapi.com/nominatim/v1/search.php?json_callback={c}&q={s}&format=json&osm_type=N&limit=100';
	//third party jsonp service	

	function filterCall(rawjson) {	//callback that remap fields name
		var json = {},
			key, loc;
		
		//console.log(rawjson);
	
		for(var i in rawjson)
		{
			key = rawjson[i].display_name;	//search key
			loc = L.latLng( rawjson[i].lat, rawjson[i].lon );
			json[ key ]= loc;	//key,value format
		}
		
		return json;
	}
	
	var searchOpts = {
			searchJsonpUrl: jsonpurl,
			searchJsonpFilter: filterCall,
			animateLocation: false,
			markerLocation: true,
			autoType: false
		};
		
	map.addControl( new L.Control.Search(searchOpts) );

</script>

<div id="copy">powered by <a href="mailto:stefano.cudini@gmail.com">Stefano Cudini</a></div>
</body>
</html>
